package com.sp.transformation;

import java.io.*;

/**
 * 演示使用 InputStreamReader 转换流解决中文乱码问题
 * 将字节流 FileInputStream 转换成字符流, InputStreamReader, 指定编码 gbk/utf-8
 */
public class InputStreamReader_ {
    public static void main(String[] args) throws IOException {
        String filePath = "d:\\development\\code\\IO_Test\\news\\story2.txt";
        //1. 把FileInputStream 转换成InputStreamReader
        //2. 指定编码gbk
        InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(filePath), "gbk");
        //3. 把 InputStreamReader 转换成 BufferedReader
        BufferedReader br = new BufferedReader(inputStreamReader);
        //将2和3合在一起写
        //BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), "gbk"));
        //4. 读取
        String s = br.readLine();
        System.out.println("读取内容: " + s);


    }
}
